package com.ruoyi.storage.service.impl;

import java.util.List;

import com.ruoyi.storage.mapper.WarehouseInfoMapper;
import com.ruoyi.storage.mapper.WarehouseZoneMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.storage.mapper.WarehouseLocationMapper;
import com.ruoyi.storage.domain.WarehouseLocation;
import com.ruoyi.storage.service.IWarehouseLocationService;

/**
 * 库位管理Service业务层处理
 * 
 * @author 庞一恺
 * @date 2025-01-10
 */
@Service
public class WarehouseLocationServiceImpl implements IWarehouseLocationService 
{
    @Autowired
    private WarehouseLocationMapper warehouseLocationMapper;
    @Autowired
    WarehouseZoneMapper warehouseZoneMapper;
    @Autowired
    WarehouseInfoMapper warehouseInfoMapper;




    /**
     * 查询库位管理
     * 
     * @param locationId 库位管理主键
     * @return 库位管理
     */
    @Override
    public WarehouseLocation selectWarehouseLocationByLocationId(Integer locationId) {
        return warehouseLocationMapper.selectWarehouseLocationByLocationId(locationId);
    }

    /**
     * 查询库位管理列表
     * 
     * @param warehouseLocation 库位管理
     * @return 库位管理
     */
    @Override
    public List<WarehouseLocation> selectWarehouseLocationList(WarehouseLocation warehouseLocation, Integer uid)
    {
        Integer warehouseId = warehouseInfoMapper.getWarehouseIdByPrincipal(uid);
        if (warehouseId == null) return new java.util.ArrayList<WarehouseLocation>();
        warehouseLocation.setWarehouseId(warehouseId);
        return warehouseLocationMapper.selectWarehouseLocationList(warehouseLocation);
    }

    /**
     * 新增库位管理
     * 
     * @param areaId,quantity 库位管理
     * @return 结果
     */
    @Override
    public int insertWarehouseLocation(Integer areaId,int quantity)
    {
        List<WarehouseLocation> warehouseLocationList = new java.util.ArrayList<>();
        for (int i=0;i<quantity;i++){
            WarehouseLocation warehouseLocation = new WarehouseLocation();
            warehouseLocation.setAreaId(areaId);
            warehouseLocation.setWarehouseId(warehouseZoneMapper.selectWarehouseZoneByAreaId(areaId).getWarehouseId());
            warehouseLocationList.add(warehouseLocation);
        }
        return warehouseLocationMapper.insertWarehouseLocationList(warehouseLocationList);
    }

    /**
     * 修改库位管理
     * 
     * @param warehouseLocation 库位管理
     * @return 结果
     */
    @Override
    public int updateWarehouseLocation(WarehouseLocation warehouseLocation)
    {
        return warehouseLocationMapper.updateWarehouseLocation(warehouseLocation);
    }

    /**
     * 批量删除库位管理
     * 
     * @param locationIds 需要删除的库位管理主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseLocationByLocationIds(Integer[] locationIds)
    {
        return warehouseLocationMapper.deleteWarehouseLocationByLocationIds(locationIds);
    }

    /**
     * 删除库位管理信息
     * 
     * @param locationId 库位管理主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseLocationByLocationId(Integer locationId)
    {
        return warehouseLocationMapper.deleteWarehouseLocationByLocationId(locationId);
    }
}
